// Copyright 2008 Senary
// See credits.txt for details.

// This file is part of Omega VII.

// Omega VII is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Omega VII is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Omega VII.  If not, see <http://www.gnu.org/licenses/>.

#include <string>

#include "ObjectEffectInfo.h"

using namespace std;

ObjectEffectInfo::ObjectEffectInfo(void)
: _effectStartTimes(SFXT_NUMSFXTYPES)
{
}

ObjectEffectInfo::~ObjectEffectInfo(void)
{
}

// registers a special effect.
// Returns true if the effect is allowed to start, false otherwise
bool ObjectEffectInfo::startEffect(SfxType effectType, float totalTime)
{
	if (_effectStartTimes[effectType] == 0 ||
		_effectStartTimes[effectType] < totalTime - effectDuration(effectType)) {
			_effectStartTimes[effectType] = totalTime;
			return true;
	} else {
		return false;
	}
}


// resets a special effect
void ObjectEffectInfo::resetEffect(SfxType effectType)
{
	_effectStartTimes[effectType] = 0.0f;
}


// Returns the duration of a given effect
float ObjectEffectInfo::effectDuration(SfxType effectType) {
	switch(effectType) {
		case SFXT_OPEN_FIRE:
			return 0.3f;
			break;
		case SFXT_METHI_FIRE:
			return 0.3f;
			break;
		case SFXT_RECEIVE_DAMAGE:
			return 1.0f;
			break;
		case SFXT_SMOKE:
			return 1.0E10f; // (almost) infinity
			break;
		case SFXT_SMOKE_OFF:
			return 1.0E10f; // (almost) infinity
			break;
		case SFXT_TRAIL:
			return 0.02f;
			break;
		default:
			throw std::string("ObjectEffectInfo::effectDuration: illegal effect type!");
			break;
	}
}